/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates.commands;

import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;


public class FlywheelPIDsetspeed extends CommandBase {

    private double targetRPM;

    public FlywheelPIDsetspeed(double targetflyspeed) {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
        requires(flyPID);
        this.targetRPM = targetflyspeed;
    }

    // Called just before this Command runs the first time
    protected void initialize() {
        flyPID.reset();
        flyPID.zerohall(); //reset the hall sensor
        flyPID.zerospeed(); //reset the speed to zero
        flyPID.setSetpoint(targetRPM);
        SmartDashboard.putDouble("targetRPM = ", targetRPM);
        flyPID.enable();
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        //getPosition returns PID input value
        return Math.abs(flyPID.getPosition() - targetRPM) == 0;
    }

    // Called once after isFinished returns true
    protected void end() {
        //makes sure that wheel stops when set to speed of zero
        if (targetRPM == 0.0){
            flyPID.disable();
            //flyPID.reset();
            //flyPID.free();
        }
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
        flyPID.setSetpoint(0.0);
        flyPID.disable();
        //flyPID.reset();
        //flyPID.free();
        System.out.println("FLYPID Interupted");
        end();
    }
}
